package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.dao.mybatis.EhmInfoEvaluateMapper;
import com.aijk.ehm.model.EhmInfoEvaluate;
import com.aijk.ehm.model.EhmInfoEvaluateExample;
import com.aijk.ehm.model.qo.EhmInfoEvaluateQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EhmInfoEvaluateService {
    private static Logger logger = LoggerFactory.getLogger(EhmInfoEvaluateService.class);

    @Autowired
    private EhmInfoEvaluateMapper mapper;

    public EhmInfoEvaluateExample getExample(EhmInfoEvaluateQo qo) {
        EhmInfoEvaluateExample example = new EhmInfoEvaluateExample();
        EhmInfoEvaluateExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (qo.getStartTime()!= null) criteria.andEvaluateTimeGreaterThanOrEqualTo(qo.getStartTime());
            if (qo.getEndTime()!= null) criteria.andEvaluateTimeLessThanOrEqualTo(qo.getEndTime());
            if (qo.getNewsid()!= null) criteria.andNewsidEqualTo(qo.getNewsid());
        }
        return example;
    }

    public int count(EhmInfoEvaluateQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(EhmInfoEvaluate bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(EhmInfoEvaluate bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public EhmInfoEvaluate findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<EhmInfoEvaluate> find(EhmInfoEvaluateQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<EhmInfoEvaluate> page(PagingRequest pagingRequest, EhmInfoEvaluateQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<EhmInfoEvaluate>(mapper.selectByExample(getExample(qo)));
    }
}